import 'package:equatable/equatable.dart';
import 'package:excel_utils/pages/week/bean/QuotationRecordBean.dart';
import 'package:excel_utils/repository/week/quotation_record_repository.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

part 'quotation_record_state.dart';

class QuotationRecordCubit extends Cubit<QuotationRecordState> {
  QuotationRecordRepository quotationRecordRepository;
  QuotationRecordCubit(this.quotationRecordRepository) : super(QuotationRecordInitial());

  saveQuotationRecord({required List<QuotationRecordBean> quotationRecord}) async {
    emit(QuotationRecordSaveLoading());
    List<QuotationRecordBean> quotationRecordData = await quotationRecordRepository.saveQuotationRecordData(quotationRecordData:quotationRecord);
    emit(QuotationRecordSaveSuccessState(quotationRecordData: quotationRecordData));
  }

  getQuotationRecord({maps}) async {
    emit(QuotationRecordDataLoading());
    List<QuotationRecordBean> quotationRecordData = await quotationRecordRepository.getQuotationRecordData(maps: maps);
    emit(QuotationRecordDataSuccessState(quotationRecordData: quotationRecordData));
  }

   deleteQuotationRecord({required String quotationRecordId}) async {
    emit(QuotationRecordDeleteLoading(quotationRecordId: quotationRecordId));
    String deleteQuotationRecordId = await quotationRecordRepository.deleteQuotationRecordData(quotationRecordId: quotationRecordId);
    if (deleteQuotationRecordId != "-1") {
      emit(QuotationRecordDeleteSuccessState(quotationRecordId: deleteQuotationRecordId));
    } else {
      emit(QuotationRecordDeleteFailureState(message: "删除失败", quotationRecordId: quotationRecordId));
    }
  }
}
